<html>
<head><meta charset="utf-8"><title>after_expansion callback · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/after_expansion.20callback.html">after_expansion callback</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="170837336"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/after_expansion%20callback/near/170837336" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Igor Matuszewski <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/after_expansion.20callback.html#170837336">(Jul 14 2019 at 15:08)</a>:</h4>
<p>Hey <span class="user-mention" data-user-id="116466">@Zoxc</span>, I'm trying to only run expansion as part of the rustc routine and I'm having some trouble driving it myself without panicking the compiler and I'm not sure I'm doing things right</p>



<a name="170837390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/after_expansion%20callback/near/170837390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Igor Matuszewski <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/after_expansion.20callback.html#170837390">(Jul 14 2019 at 15:10)</a>:</h4>
<p>Right now there are only <code>after_parsing</code> and <code>after_analysis</code> callbacks available - I figured I'd just do <code>register_plugins()</code> and <code>expansion()</code> but it seems that I can't really do these in callbacks since that already sets thread locals and panics afterwards</p>



<a name="170837397"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/after_expansion%20callback/near/170837397" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Igor Matuszewski <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/after_expansion.20callback.html#170837397">(Jul 14 2019 at 15:11)</a>:</h4>
<p>reason behind it is I want to expand the crate so I know every input file used in the compilation so I can associate it with a given crate (incl. name, disambiguator and edition)</p>



<a name="170837462"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/after_expansion%20callback/near/170837462" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/after_expansion.20callback.html#170837462">(Jul 14 2019 at 15:12)</a>:</h4>
<p>Is this for RLS?</p>



<a name="170837533"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/after_expansion%20callback/near/170837533" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Igor Matuszewski <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/after_expansion.20callback.html#170837533">(Jul 14 2019 at 15:15)</a>:</h4>
<p>yes</p>



<a name="170837578"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/after_expansion%20callback/near/170837578" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Igor Matuszewski <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/after_expansion.20callback.html#170837578">(Jul 14 2019 at 15:16)</a>:</h4>
<p>ideally I wouldn't copy-paste most of the code from librustc_driver into the RLS if that would help avoid the ordering problems</p>



<a name="170837580"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/after_expansion%20callback/near/170837580" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Igor Matuszewski <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/after_expansion.20callback.html#170837580">(Jul 14 2019 at 15:16)</a>:</h4>
<p>I'm also not sure the approach is correct, please correct me if I'm wrong</p>



<a name="170837634"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/after_expansion%20callback/near/170837634" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Igor Matuszewski <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/after_expansion.20callback.html#170837634">(Jul 14 2019 at 15:18)</a>:</h4>
<p>right now we collect the file -&gt; (crate, disambiguator, edition) mapping in <code>after_analysis</code> but this leads to a weird case where we don't invoke the callback when compilation fails (e.g. due to a type mismatch) and we need the file edition data to correctly format them with rustfmt</p>



<a name="170837637"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/after_expansion%20callback/near/170837637" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Igor Matuszewski <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/after_expansion.20callback.html#170837637">(Jul 14 2019 at 15:18)</a>:</h4>
<p>(so currently code has to compile in order to be able to being formatted which is... less than ideal)</p>



<a name="170837688"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/after_expansion%20callback/near/170837688" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Igor Matuszewski <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/after_expansion.20callback.html#170837688">(Jul 14 2019 at 15:20)</a>:</h4>
<p>(and <code>after_parsing</code> isn't enough, since code can invoke a <code>macro_rules! include_my_mod { () =&gt; { mod some_mod; }; }</code> and then <code>some_mod.rs</code> isn't included in the list)</p>



<a name="170837881"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/after_expansion%20callback/near/170837881" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/after_expansion.20callback.html#170837881">(Jul 14 2019 at 15:27)</a>:</h4>
<p>You could probably just add another callback for RLS.</p>



<a name="170838169"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/after_expansion%20callback/near/170838169" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Igor Matuszewski <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/after_expansion.20callback.html#170838169">(Jul 14 2019 at 15:36)</a>:</h4>
<p>okay, I'll look into it.</p>



<a name="170838193"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/after_expansion%20callback/near/170838193" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Igor Matuszewski <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/after_expansion.20callback.html#170838193">(Jul 14 2019 at 15:38)</a>:</h4>
<p>By the way, maybe it'd be more readable to move <a href="https://github.com/rust-lang/rust/blob/87b103d4a99193bf57a17866fb99596df7d31d8b/src/librustc_driver/lib.rs#L457" target="_blank" title="https://github.com/rust-lang/rust/blob/87b103d4a99193bf57a17866fb99596df7d31d8b/src/librustc_driver/lib.rs#L457">Compilation</a> into interface and use this instead as the return type in the callbacks? Returning <code>true</code> seems somewhat vague and I found myself commenting what it does</p>



<a name="170839584"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/after_expansion%20callback/near/170839584" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Zoxc <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/after_expansion.20callback.html#170839584">(Jul 14 2019 at 16:22)</a>:</h4>
<p>Yeah, that could be used instead of the bools</p>



<a name="170846500"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/after_expansion%20callback/near/170846500" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Igor Matuszewski <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/after_expansion.20callback.html#170846500">(Jul 14 2019 at 20:03)</a>:</h4>
<p>Done, filed <a href="https://github.com/rust-lang/rust/pull/62679" target="_blank" title="https://github.com/rust-lang/rust/pull/62679">https://github.com/rust-lang/rust/pull/62679</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>